package com.wall.haven.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.wall.haven.config.SystemConfigCache;
import com.wall.haven.dto.SystemDataDTO;
import com.wall.haven.service.ProxyService;
import com.wall.haven.service.SystemService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URISyntaxException;

@RestController
@RequestMapping("/system")
public class SystemController {

    @Resource
    private SystemService systemService;

    @Resource
    private ProxyService proxyService;

    @Resource
    private SystemConfigCache systemConfigCache;


    @GetMapping("/global")
    public R<SystemDataDTO> global() {
        return R.ok(systemService.systemData());
    }

    @GetMapping("/reload-config")
    public R<Boolean> reloadConfig() {
        systemConfigCache.load();
        return R.ok(true);
    }

    @RequestMapping("/test-file")
    public void test(@RequestParam String path, HttpServletResponse response) throws URISyntaxException, IOException {
        proxyService.test(path,response);
    }
}
